/*
 * ******************************************************************************
 *   Copyright © 2013-2014 sean.yanghy. All rights reserved.
 *  *****************************************************************************
 */

package com.exteam.common.network;

import android.content.Intent;

import org.apache.http.NameValuePair;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;

/**
 * 数据资源中心
 *
 * @author sean.yanghy
 * @version v1.0
 * @created 2014-07-06 13:56:23
 */
public class HttpIntent extends Intent {

    public static final String URI = "uri";
    public static final String URL = "urL";
    public static final String POST_PARAMS = "post_params";

    public static final String METHOD = "method";

    public static final String IS_SET_COOKIE = "is_set_cookie";

    public static final String READ_TIMEOUT = "read_timeout";

    public static final String CONNECT_TIMEOUT = "connect_timeout";

    public List<NameValuePair> params;
    public JSONObject paramJSONObject;
    public Map<String, String> headers;

    /**
     * 是否缓存接口返回数据到本地
     */
    public static final String IS_CACHE_DATA = "is_cache_data";

    // private Object parseObject;


    public HttpIntent(String url, List<NameValuePair> params) {
        putExtra(URL, url);
        this.params = params;
    }

    public HttpIntent(String url, JSONObject paramJSONObject) {
        putExtra(URL, url);
        this.paramJSONObject = paramJSONObject;
    }

    public HttpIntent(String uri) {
        this(uri, IRequest.METHOD_GET, false, true);
    }


    public HttpIntent(String uri, String reqMethod) {
        this(uri, reqMethod, false, true);
    }

    public HttpIntent(String uri, boolean isSetCookie) {
        this(uri, IRequest.METHOD_GET, isSetCookie, true);
    }

    public HttpIntent(String uri, boolean isSetCookie, boolean isCacheData) {
        this(uri, IRequest.METHOD_GET, isSetCookie, isCacheData);
    }

    public HttpIntent(String uri, String reqMethod, boolean isSetCookie) {
        this(uri, reqMethod, isSetCookie, true);
    }

    public HttpIntent(boolean isAdIntent, String uri) {
        this(uri, IRequest.METHOD_GET, false, true);
    }

    public HttpIntent(String uri, String reqMethod, boolean isSetCookie,
                      boolean isCacheData) {
        putExtra(URI, uri);
        putExtra(METHOD, reqMethod);
        putExtra(IS_SET_COOKIE, isSetCookie);
        putExtra(IS_CACHE_DATA, isCacheData);
        putExtra(CONNECT_TIMEOUT, 10000);
        putExtra(READ_TIMEOUT, 10000);
    }

    /**
     * connectTimeout
     * the connectTimeout to set
     */
    public HttpIntent setConnectTimeout(int connectTimeout) {
        putExtra(CONNECT_TIMEOUT, connectTimeout);
        return this;
    }

    /**
     * readTimeout
     * the readTimeout to set
     */
    public HttpIntent setReadTimeout(int readTimeout) {
        putExtra(READ_TIMEOUT, readTimeout);
        return this;
    }

    /**
     * 设置是否需要缓存接口数据，缺省值是true
     * <p/>
     * isCache
     */
    public HttpIntent setCache(boolean isCacheData) {
        putExtra(IS_CACHE_DATA, isCacheData);
        return this;
    }

    // public void putParseObject(Object o) {
    // parseObject = o;
    // }
    //
    // public Object getParseObject() {
    // return parseObject;
    // }

}
